
#include "setting_up_err.h"
#include "sys_font.h"
#include "pt_fs.h"

static ui_setting_up_err_t  ui_set_up_err;


static  char * icon_up_err[1] = 
{
    "Warning.png",
};


static int setting_up_err_close_clicked_event(void)
{
    page_pop_anim_name(LOAD_ANIM_MOVE_LEFT,"setting2");
    root_gesture_enable();
    return 0;
}

static void setting_up_err_close_event_callback(lv_event_t* event)
{
    if (event->code == LV_EVENT_CLICKED) {

        debug_d("up close clicked\n");
        setting_up_err_close_clicked_event();
    }
}

static int setting_up_err_try_clicked_event(void)
{
    page_pop_anim_name(LOAD_ANIM_MOVE_LEFT,"setting_download");
    return 0;
}

static void setting_up_err_try_event_callback(lv_event_t* event)
{
    if (event->code == LV_EVENT_CLICKED) {

        debug_d("up try clicked\n");
        setting_up_err_try_clicked_event();
    }
}


int ui_setting_up_err_create(lv_obj_t *superview)
{
    char txt_buff[256];
    
    ui_set_up_err.img_tip = lv_img_create(superview);
    lv_img_set_src(ui_set_up_err.img_tip,pt_fs_get(icon_up_err[0]));
    lv_obj_set_pos(ui_set_up_err.img_tip,200,52);
    //**********************************************************************************************
    ui_set_up_err.lab_tip = lv_label_create(superview);
    lv_obj_set_pos(ui_set_up_err.lab_tip,24,156);
    lv_obj_set_size(ui_set_up_err.lab_tip,432,40);
    lv_obj_set_style_text_align(ui_set_up_err.lab_tip,LV_TEXT_ALIGN_CENTER,0);
    lv_obj_set_style_text_opa(ui_set_up_err.lab_tip,LV_OPA_100,LV_PART_MAIN);
    lv_obj_set_style_text_color(ui_set_up_err.lab_tip,lv_color_make(0xff,0xff,0xff),LV_PART_MAIN); 
    lv_obj_set_style_text_font(ui_set_up_err.lab_tip, lv_font_get(20), LV_STATE_DEFAULT);
    lv_label_set_text( ui_set_up_err.lab_tip, "更新失败，请检查网络连接。");
    //**********************************************************************************************
    //close btn

    ui_set_up_err.bg_close = lv_obj_create(superview);

    lv_obj_set_pos(ui_set_up_err.bg_close,60,246);
    lv_obj_set_size(ui_set_up_err.bg_close,170,50);

	lv_obj_set_style_radius(ui_set_up_err.bg_close, 25, LV_PART_MAIN);
	lv_obj_set_style_border_width(ui_set_up_err.bg_close, 0, LV_PART_MAIN);
	lv_obj_set_style_border_color(ui_set_up_err.bg_close, lv_color_make(0x00, 0x00, 0x00), LV_PART_MAIN);
	lv_obj_set_style_border_opa(ui_set_up_err.bg_close, LV_OPA_0, LV_PART_MAIN);

	lv_obj_set_style_outline_width(ui_set_up_err.bg_close, 0, LV_PART_MAIN);
	lv_obj_set_style_shadow_width(ui_set_up_err.bg_close, 0, LV_PART_MAIN);
	lv_obj_set_scrollbar_mode(ui_set_up_err.bg_close, LV_SCROLLBAR_MODE_OFF);
	lv_obj_set_style_pad_all(ui_set_up_err.bg_close, 0,0);
    
    #if 0
    lv_obj_set_style_bg_opa(ui_set_up_err.bg_close,LV_OPA_0,0);
    #else
    lv_obj_set_style_bg_opa(ui_set_up_err.bg_close,LV_OPA_100,0);
    lv_obj_set_style_bg_color(ui_set_up_err.bg_close,lv_color_make(0x26,0x7a,0xff),0);
    #endif 

    lv_obj_add_event_cb(ui_set_up_err.bg_close, setting_up_err_close_event_callback, LV_EVENT_ALL, NULL);
    //**********************************************************************************************
    ui_set_up_err.lab_close = lv_label_create(ui_set_up_err.bg_close);
    lv_obj_set_pos(ui_set_up_err.lab_close,0,5);
    lv_obj_set_size(ui_set_up_err.lab_close,170,30);
    lv_obj_set_style_text_align(ui_set_up_err.lab_close,LV_TEXT_ALIGN_CENTER,0);
    lv_obj_set_style_text_opa(ui_set_up_err.lab_close,LV_OPA_100,LV_PART_MAIN);
    lv_obj_set_style_text_color(ui_set_up_err.lab_close,lv_color_make(0xff,0xff,0xff),LV_PART_MAIN); 
    lv_obj_set_style_text_font(ui_set_up_err.lab_close, lv_font_get(28), LV_STATE_DEFAULT);

    lv_label_set_text(ui_set_up_err.lab_close,"关闭");
    //**********************************************************************************************
    //**********************************************************************************************
    //try btn

    ui_set_up_err.bg_try = lv_obj_create(superview);

    lv_obj_set_pos(ui_set_up_err.bg_try,275,246);
    lv_obj_set_size(ui_set_up_err.bg_try,170,50);

	lv_obj_set_style_radius(ui_set_up_err.bg_try, 25, LV_PART_MAIN);
	lv_obj_set_style_border_width(ui_set_up_err.bg_try, 0, LV_PART_MAIN);
	lv_obj_set_style_border_color(ui_set_up_err.bg_try, lv_color_make(0x00, 0x00, 0x00), LV_PART_MAIN);
	lv_obj_set_style_border_opa(ui_set_up_err.bg_try, LV_OPA_0, LV_PART_MAIN);

	lv_obj_set_style_outline_width(ui_set_up_err.bg_try, 0, LV_PART_MAIN);
	lv_obj_set_style_shadow_width(ui_set_up_err.bg_try, 0, LV_PART_MAIN);
	lv_obj_set_scrollbar_mode(ui_set_up_err.bg_try, LV_SCROLLBAR_MODE_OFF);
	lv_obj_set_style_pad_all(ui_set_up_err.bg_try, 0,0);
    
    #if 0
    lv_obj_set_style_bg_opa(ui_set_up_err.bg_try,LV_OPA_0,0);
    #else
    lv_obj_set_style_bg_opa(ui_set_up_err.bg_try,LV_OPA_100,0);
    lv_obj_set_style_bg_color(ui_set_up_err.bg_try,lv_color_make(0x26,0x7a,0xff),0);
    #endif 

    lv_obj_add_event_cb(ui_set_up_err.bg_try, setting_up_err_try_event_callback, LV_EVENT_ALL, NULL);
    //**********************************************************************************************
    ui_set_up_err.lab_try = lv_label_create(ui_set_up_err.bg_try);
    lv_obj_set_pos(ui_set_up_err.lab_try,0,5);
    lv_obj_set_size(ui_set_up_err.lab_try,170,30);
    lv_obj_set_style_text_align(ui_set_up_err.lab_try,LV_TEXT_ALIGN_CENTER,0);
    lv_obj_set_style_text_opa(ui_set_up_err.lab_try,LV_OPA_100,LV_PART_MAIN);
    lv_obj_set_style_text_color(ui_set_up_err.lab_try,lv_color_make(0xff,0xff,0xff),LV_PART_MAIN); 
    lv_obj_set_style_text_font(ui_set_up_err.lab_try, lv_font_get(28), LV_STATE_DEFAULT);

    lv_label_set_text(ui_set_up_err.lab_try,"再试一次");
    //**********************************************************************************************


    return 0;
}


int ui_setting_up_err_destroy(lv_obj_t *superview)
{
    
    if(ui_set_up_err.img_tip){
        lv_obj_del(ui_set_up_err.img_tip);
        ui_set_up_err.img_tip = NULL;
    }
    if(ui_set_up_err.lab_tip){
        lv_obj_del(ui_set_up_err.lab_tip);
        ui_set_up_err.lab_tip = NULL;
    }   
    if(ui_set_up_err.bg_close){
        lv_obj_del(ui_set_up_err.bg_close);
        ui_set_up_err.bg_close = NULL;
        ui_set_up_err.lab_close = NULL;
    }   
    if(ui_set_up_err.bg_try){
        lv_obj_del(ui_set_up_err.bg_try);
        ui_set_up_err.bg_try = NULL;
        ui_set_up_err.lab_try = NULL;
    } 

    return 0;
}



static void setting_up_err_on_view_did_load(page_base_t* self)
{
    ui_setting_up_err_create(self->root);
}

static void setting_up_err_on_view_did_unload(page_base_t* self)
{
    ui_setting_up_err_destroy(self->root);
}



static page_vtable_t setting_up_err_param = {
    .on_custom_attr_config  = NULL,
    .on_view_load           = NULL,
    .on_view_did_load       = setting_up_err_on_view_did_load,
    .on_view_will_appear    = NULL,
    .on_view_did_appear     = NULL,
    .on_view_will_disappear = NULL,
    .on_view_did_disappear  = NULL,
    .on_view_did_unload     = setting_up_err_on_view_did_unload,
};


page_vtable_t* lv_page_setting_up_err_create(void)
{
    return &setting_up_err_param;
}
